<?php
/**
 *      [迷你云] (C)2009-2012 南京恒为网络科技.
 *   软件仅供研究与学习使用，如需商用，请访问www.miniyun.cn获得授权
 * 
 */
?>
<?php

class UserStatForm extends CMiniyunStatForm
{
	protected  function chartMethods(){
		return array("chartPie","chartHistogram");
	}
	
	public function chartPie(){
	 $dbCommand = Yii::app()->db->createCommand("SELECT count(*) as userCount,user_status  FROM `".Yii::app()->params['tablePrefix']."users` where created_at>='".$this->startDate." 00:00:00' and created_at<='".$this->endDate." 23:59:59' group by user_status");
	 $data =  $dbCommand->queryAll();
	 $enabledUserCount = 0;
	 $disbledUserCount = 0;
	 foreach($data as $index=>$item){
	 	if($item["user_status"]==1){
	 		$enabledUserCount = $item["userCount"];
	 	}else{
	 		$disbledUserCount = $item["userCount"];
	 	}
	 }
	 	 	 $charOptions = array(
	  'theme' => 'gray',
	  'title' => array('text' => '实时用户分布图'),
      'tooltip' => array(
			   'formatter' => 'js:function(){ return \'<b>\'+ this.point.name +\'</b>: \'+ this.y +\' 位 ，占\'+ForDight(this.percentage,1) +\' %\';}' 
			   ),
      'series' => array( 
			   array(
         'type' => 'pie',
         'data' => array(
			   array('正常用户',(int)$enabledUserCount),
			   array('冻结用户',(int)$disbledUserCount),
			   ),
			   )
			   )
			   );
	  return $charOptions;
			 
	}
	 
	
	public function chartHistogram(){
		$data = parent::getSampleHistogramData();
		$charOptions = array(
		'theme' => 'gray',
        'title' => array('text' => '注册用户数直方图'),
        'xAxis' => array(
           'categories' => array_keys($data)
		),
        'yAxis' => array(
           'title' => array('text' => '用户数')
		),
        'series' => array(
		  array('name' => '当前用户数', 'data' => array_values($data)), 
		)
		);
		return $charOptions;
	}
}